{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% import "brand/partial/brand_model_table.html" as brand_table_macro %}
{% import "brand/partial/search_brand_model_form.html" as search_brand_form_macro %}


{% block title %}万屏时代报价工具--品牌型号列表{% endblock %}

{% block panel_heading %}
  万屏时代报价工具--品牌型号列表
  <div class="pull-right btn-group">
    <a href="{{ url_for('product_bp.add_brand_model') }}"
       class="btn btn-xs btn-success"
       style="margin-right: 5px;" target="_self">
        新增型号品牌
    </a>
  </div>
{% endblock %}

{% block panel_body %}
    {{ search_brand_form_macro.gen_form(search_form) }}
    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, 'product_bp.brand_model_list', **url_kwargs) }}
    </div>
    {% endif %}

    {{ brand_table_macro.gen_table(brand_models, current_user, url_kwargs) }}

    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, 'product_bp.brand_model_list', **url_kwargs) }}
    </div>
    {% endif %}
{% endblock %}

{% block scripts %}
    {{ super() }}
    <script>
        function get_brands_by_type() {
            var product_type_id = $('#product_type_id').val();
            $.ajax({
                url: "{{ url_for('product_bp.ajax_brand_choices')}}",
                data: JSON.stringify({
                    'product_type_id': product_type_id
                }),
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                cache: true
            }).done(function (data) {
                $("#brand_id").empty();
                for (var i = 0; i < data.length; i++) {
                    var id = data[i][0];
                    var name = data[i][1];
                    $("#brand_id").append(
                        "<option value='" + id + "'>" + name + "</option>"
                    );
                }

            }).fail(function () {
                $(obj).data('content', '服务器错误');
                $(obj).popover('show');
            });
        }
        $(document).ready(function () {
            $("#product_type_id").change(function () {
                get_brands_by_type();
            });
            var product_type_id = $("#product_type_id").val();
            if (product_type_id != 0) {
                get_brands_by_type();
            }
        })
    </script>
{% endblock %}

